const observer = new MutationObserver(function (mutationsList, observer) {
    // 若`mutationsList`非空，说明检测到了变化
    for (let mutation of mutationsList) {
        if (mutation.type === 'childList') {
            // 在这里执行你需要的方法
            window.setTimeout(closeWatchLater,100)
            closeAD();
        }
    }
});

function closeWatchLater() {
    let watchLaterList = document.getElementsByClassName("bili-watch-later--wrap");
    for (let i = 0; i < watchLaterList.length; i++) {
        let watchLater = watchLaterList[i];
        watchLater.style.display = "none";
    }
}

function closeAD() {
    let cardList = document.getElementsByClassName("bili-video-card");
    for (let i = 2; i < cardList.length; i++) {
        let card = cardList[i];
        if (!card.className.includes("enable-no-interest")) {
            card.style.display = "none"
        }
    }
}
// 监听DOM加载完成
window.onload =  function () {
    closeAD();
    closeWatchLater();
    // 缓存查询结果，避免重复查询
    const contentContainerElements = document.getElementsByClassName("container");



    try {
        // 获取监听目标节点
        const contentContainer = contentContainerElements.length > 0 ? contentContainerElements[0] : null;

        // 使用配置文件调用 observe 方法
        const config = { attributes: false, childList: true, subtree: false };

        // 开始监听
        if (contentContainer !== null) {
            observer.observe(contentContainer, config);
        }
    } catch (error) {
        console.error("发生错误：", error);
    }
}

const adBannerElements = document.getElementsByClassName("adblock-tips");
// 隐藏横幅
if (adBannerElements.length > 0) {
    adBannerElements[0].style.display = "none";
}
